// pages/feedback/feedback.js
const app = getApp();
const {
  feedback
} = require('../../config.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    radioChange: '2',
    inputValue: '',
    textAreaValue: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  radioChange(e) {
    this.setData({
      radioChange: e.detail.value
    })
  },
  bindKeyInput(e) {
    console.log(e.detail.value)
    this.setData({
      inputValue: e.detail.value
    })
  },
  bindInputTextArea(e) {
    console.log(e.detail.value)
    this.setData({
      textAreaValue: e.detail.value
    })
  },
  feedBack(){
    let data = { type: this.data.radioChange, contact: this.data.inputValue, details: this.data.textAreaValue};
    if (!data.contact || !data.details){
      wx.showToast({
        title: '请填写完整信息',
        icon: 'none'
      })
      return
    }else{
      if (!(/^1\d{10}$/.test(data.contact))){
        wx.showToast({
          title: '请输入正确手机号',
          icon: 'none'
        })
        return;
      }
      app.appRequest({
        url: feedback,
        method: 'POST',
        data: {
          ...data
        },
        success: (res) => {
          console.log(res)
          if (res.code == 0) {
            wx.showToast({
              title: '反馈成功',
              icon: 'none',
            })
            setTimeout( ()=> {
              wx.switchTab({
                url: '/pages/my/my'
              });
            },1000)
          }
        }
      })
    }
  }
  
})